package huawei.ran;

import java.util.Arrays;

public class J1024 {
    public int videoStitching(int[][] clips, int time) {
        int[] tmp =new int[time+1];
        for(int[] clip:clips){
            if(clip[0]<=time){
                tmp[clip[0]]=Math.max(tmp[clip[0]],clip[1]);
            }
        }
        int last=0;
        int res=0;
        int pre =0;
        System.out.println(Arrays.toString(tmp));
        for (int i = 0; i <=time; i++) {
            last=Math.max(last,tmp[i]);
            if(i==last){//无法向右扩展
                return -1;
            }
            if(pre==i){
                pre=last;
                res++;
            }
            if(last>=time){
                return res;
            }
        }
        return res;
    }
}
